/*
 * @Author: AuroCaffe 18509564594@163.com
 * @Date: 2025-07-23 11:43:27
 * @LastEditors: AuroCaffe 18509564594@163.com
 * @LastEditTime: 2025-07-23 14:32:55
 * @FilePath: \HuiLin\api\productOrder.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
	http,
	Method
} from "@/utils/request.js";

import api from "@/config/api.js";

/**
 * 创建商品订单
 * @param {Object} orderData 订单数据
 */
export function createProductOrder(orderData) {
	return http.request({
		url: '/product-orders',
		method: Method.POST,
		data: orderData
	});
}

/**
 * 支付商品订单
 * @param {String} orderId 订单ID
 * @param {String} openid 用户openid
 */
export function payProductOrder(orderId, openid) {
	return http.request({
		url: `/product-orders/${orderId}/pay`,
		method: Method.POST,
		data: {
			id: orderId,
			openid: openid
		}
	});
}

/**
 * 查询订单支付状态
 * @param {String} orderId 订单ID
 */
export function queryProductOrderPayment(orderId) {
	return http.request({
		url: `/product-orders/${orderId}/query-payment`,
		method: Method.POST,
		data: {
			id: orderId
		}
	});
}

/**
 * 查询多店铺订单支付状态
 * @param {String} shopId 店铺ID
 */
export function queryMultiShopOrderPayment(outTradeNo) {
	return http.request({
		url: `/orders/multi-pay/query-payment`,
		method: Method.POST,
		data: {
			outTradeNo: outTradeNo
		}
	});
}

/**
 * 批量查询订单支付状态
 * @param {Array} orderIds 订单ID数组
 */
export function batchQueryProductOrderPayment(orderIds) {
	return http.request({
		url: '/product-orders/batch-query-payment',
		method: Method.POST,
		data: {
			orderIds: orderIds
		}
	});
}

/**
 * 获取商品订单列表
 * @param {Object} params 查询参数
 */
export function getProductOrderList(params) {
	return http.request({
		url: '/product-orders',
		method: Method.GET,
		data: params
	});
}

/**
 * 获取商品订单详情
 * @param {String} orderId 订单ID
 */
export function getProductOrderDetail(orderId) {
	return http.request({
		url: `/product-orders/${orderId}`,
		method: Method.GET
	});
}

/**
 * 取消商品订单
 * @param {String} orderId 订单ID
 * @param {String} reason 取消原因
 */
export function cancelProductOrder(orderId, reason) {
	return http.request({
		url: `/product-orders/${orderId}/cancel`,
		method: Method.POST,
		data: {
			orderId: orderId,
			reason: reason
		}
	});
}

/**
 * 确认收货
 * @param {String} orderId 订单ID
 */
export function receiveProductOrder(orderId) {
	return http.request({
		url: `/product-orders/${orderId}/receive`,
		method: Method.POST,
		data: {
			id: orderId
		}
	});
}

/**
 * 创建多店铺订单并支付
 * @param {Object} multiShopOrderData 多店铺订单数据
 */
export function createMultiShopOrderAndPay(multiShopOrderData) {
	return http.request({
		url: '/orders/multi-pay',
		method: Method.POST,
		data: multiShopOrderData
	});
}